#include <stdio.h>
#include "uevent.h"

int count_1 = 0;
int count_2 = 0;
static UEventLoop *g_loop = NULL;

void _TimerProc(int timer_id, void *arg) {
    int *count = (int*)arg;
    (*count) ++;
    printf("%d:====%d====\n", timer_id, *count);
}

void _TimerProc_2(int timer_id, void *arg) {
    UEvent_BreakLoop(g_loop);
}

void _TimerProc_1(int timer_id, void *arg) {
    puts("=== stop ===");
    UEvent_StopTimer(g_loop, 1);
    UEvent_StopTimer(g_loop, 2);

    UEventTimerDetail detail_3 = {_TimerProc_2, NULL};
    UEvent_RunAfter(g_loop, 1, 30000, &detail_3);
}

int test_timer_install(UEventLoop *loop) {
    g_loop = loop;
    UEventTimerDetail detail_1 = {_TimerProc, &count_1};
    UEvent_RunEvery(loop, 1, 100, &detail_1);

    UEventTimerDetail detail_2 = {_TimerProc, &count_2};
    UEvent_RunTimer(loop, 2, 1500, 1000, &detail_2);

    UEventTimerDetail detail_3 = {_TimerProc_1, NULL};
    UEvent_RunAfter(loop, 3, 5000, &detail_3);
    return 0;
}
